import pandas as pd
# pd.set_option('display.unicode.east_asian_width',True)
# df=pd.read_excel('hhh.xlsx')
# df1=pd.pivot_table(df,values='消费金额',index='性别',columns='产品类型',aggfunc='sum',margins=True,margins_name='总消费')
# print('统计和汇总性别、产品类型及总消费的数据df1:\n',df1)
# df2=pd.pivot_table(df,values='消费金额',index='性别',columns='产品类型')
# print('统计和汇总性别、产品类型及平均消费的数据df2:\n',df2)

# import numpy as np
# import pandas as pd
# data1=np.random.randint(1,7,10000)
# data2=np.random.randint(1,7,10000)
# arr=data1+data2
# df=pd.DataFrame(data1+data2)
# count=df.value_counts().sort_index()
# print('两个骰子抛掷数字和的统计结果:\n',count)
# print('偏度：',df.skew().iloc[0])
# print('峰度:',df.kurt().iloc[0])


import pandas as pd
pd.set_option('display.unicode.east_asian_width',True)
df=pd.read_excel('12.xlsx')
df['投放时间']=pd.to_datetime(df['投放时间']).dt.hour
df1=df.groupby('渠道').agg({'价格（元）':'sum'})
df1['排名']=df1.rank(method='first',ascending=False)
df1.sort_values(by='排名',ascending=True,inplace=True)
print('按渠道的总额降序排名，以及按排名升序排列:\n',df1)
df2=pd.crosstab(index=df['渠道'],columns=df['是否点击'],margins_name='比例',margins=True,normalize=True)
print(df2)
df3=df[['年龄层次','城市等级','价格（元）','投放时间']]
print(df3.corr())
